package Java2Test.mythread.threadtest2;

public class MyRunnable implements Runnable {

    static int gift = 100;
    static int count = 0;

    @Override
    public void run() {
        while (true) {
            synchronized (MyRunnable.class) {
                if (gift < 10) {
                    System.out.println("礼物小于10份不再送出");
                    break;//礼物小于10份不再送出
                } else {
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    gift--;
                    count = 100 - gift;
                    System.out.println(Thread.currentThread().getName()
                            + "正在发第" + count + "份礼物, 还剩" + gift + "份礼物");
                }
            }
        }
    }
}
